package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan int, 5)
	go func() {
		for i := 0; i < 8; i++ {
			ch <- i
			fmt.Printf("i:%d,len(ch):%d,cap(ch):%d\n", i, len(ch), cap(ch))
		}
		close(ch)
	}()

	time.Sleep(3 * time.Second)
	for i := 0; i < 8; i++ {
		v := <-ch
		fmt.Printf("<-chan:%d\n", v)
	}

	for {

		if v, ok := <-ch; ok == true {
			fmt.Println("读到数据：", v)
		} else {
			fmt.Println("chan  已关闭")
			break
		}
	}
}
